<template>
	<view>
		<view>
			<table-title content="我的收藏列表"></table-title>
			<discovy-record v-for="(item,index) in recordList" :key="index" :title="item.title" :city="item.areaName" :building="item.buildingName" :desc="item.desc" :readCnt="item.readingQuantity" :time="item.showStartDate" :imgUrl="item.imgUrl" @getClick="checkDetails(index)"></discovy-record>
		</view>
	</view>
</template>

<script>
	import {
		syncGetOrderList,
		ONLINE_SERVER_ADDRESS_BASE
	} from "../../../util/network.js"
	export default {
		data() {
			return {
				token:'',
				userInfo:[],
				current: 0,
				background : {
					backgroundColor : '#FFFFFF'
				},
				testing:true,
				choosedState: '商家展示',
				navChoice: ['商家展示','新政发布'],
				isActive: ['active-choice-contract','nav-choice-contract'],
				activeIndex: 0,
				pageNo:1,
				pageSize:10,
				isLoadMore:false,  //是否加载中
				loadStatus:'loading',  //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				recordList:[
					{'id':0,'type':0,'title':'这是一个测试','desc':'    （点击查看详细政策描述）','areaName':'深圳市','buildingName':'中科大厦','readingQuantity':35,'showStartDate':'2022年1月22日','imgUrl':'/static/rule.png'},
					{'id':0,'type':0,'title':'这是一个测试','desc':'    （点击查看详细政策描述）','areaName':'上海市','buildingName':'中科大厦','readingQuantity':35,'showStartDate':'2022年1月22日','imgUrl':'/static/rule.png'}
				],
				
				filterData:[
					{
						"name":'全部分类',
						"type": 'hierarchy-column',
						"submenu": [{
								"name": '全部城市',
								"value": 0,
								"submenu": [{
												"name": "全部楼盘",
												"value": 0
											}]
								},
							]
					},
				],
				areaId:0,
				buildId:0,
				industryId:0,
				HMfilterDropdownTop:0,
				previewUrl:`${ONLINE_SERVER_ADDRESS_BASE}/file/preview/`,
			}
		},
		onReachBottom() {
			if(!this.isLoadMore){
				this.isLoadMore=true
				this.pageNo+=1
				if(this.activeIndex == 0){
					this.getCompanyList()
				}else{
					this.getRuleList()
				}
			}
		},
		methods: {
			newCompany(){
				uni.navigateTo({
					url:'companyDetails/companyDetails?id=待申请' + '&state=' + '待申请'
				})
			},
			companyHistory(){
				uni.navigateTo({
					url:'companyHistory/companyHistory'
				})
			},
			collectHistory(){
				uni.navigateTo({
					url:'collectHistory/collectHistory'
				})
			},
			checkDetails(index){
				if(this.choosedState == '商家展示'){
					uni.navigateTo({
						url:'../companyDetails/companyDetails?id=' + this.recordList[index].id
					})
				}
				if(this.choosedState == '新政发布'){
					uni.navigateTo({
						url:'ruleDetails/ruleDetails?id=' + this.recordList[index].id
					})
				}
			},
			confirm(e) {
				console.log(e.index);
				console.log(e.value);
				this.pageNo = 1
				this.pageSize = 10
				this.recordList=[]
				let tempList = e.value
				if(this.activeIndex == 0){
					this.areaId = tempList[0][1]
					this.industryId = tempList[0][0]
					this.getCompanyList()
				}else{
					this.areaId = tempList[0][0]
					this.buildId = tempList[0][1]
					this.getRuleList()
				}
			},
			changeActive(e) {
				this.pageNo = 1
				this.pageSize = 10
				this.recordList=[]
				if(e!==this.activeIndex){
					let tmp = [...this.isActive]
					tmp[e] = 'active-choice-contract'
					tmp[this.activeIndex] = 'nav-choice-contract'
					this.activeIndex = e
					this.isActive = tmp
					this.choosedState = this.navChoice[this.activeIndex]
				}
				if(this.activeIndex == 0){
					this.testing = true
					this.getCompanyFilter()
				}else{
					this.testing = false
					this.getRuleFilter()
				}
			},
			
			listPush(item){
				if(this.activeIndex == 0){
					let itemTmp = {'id':0,'type':0,'title':'这是一个测试','desc':'这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试','areaName':'深圳市','buildingName':'中科大厦','readingQuantity':35,'showStartDate':'2022年1月22日','imgUrl':'/static/rule.png'}
					let companyBaseInfo = JSON.parse(item.companyBaseInfo)
					let companyExtraInfo = JSON.parse(item.extraInfo)
					itemTmp.id = item.id
					itemTmp.title = companyBaseInfo.allName
					itemTmp.desc = companyExtraInfo.desc
					itemTmp.areaName = item.areaName
					itemTmp.buildingName = item.industryName
					itemTmp.readingQuantity = item.totalCollectionQuantity + '收藏'
					itemTmp.showStartDate = item.collectTime.replace('T',' ')
					itemTmp.imgUrl = this.previewUrl + companyBaseInfo.displayLogo
					this.recordList.push(itemTmp)
				}else{
					let itemTmp = {'id':0,'type':0,'title':'这是一个测试','desc':'这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试','areaName':'深圳市','buildingName':'中科大厦','readingQuantity':35,'showStartDate':'2022年1月22日','imgUrl':'/static/rule.png'}
					itemTmp.id = item.id
					itemTmp.title = item.title
					itemTmp.desc = '    （点击查看详细政策描述）'
					itemTmp.areaName = item.areaName
					itemTmp.buildingName = item.buildName
					itemTmp.readingQuantity = item.readingQuantity + '阅读'
					itemTmp.showStartDate = item.showStartDate
					this.recordList.push(itemTmp)
				}
			},
			
			getRuleList(){
				this.isLoadMore = false
				let data = {
						pageNo:this.pageNo,
						pageSize:this.pageSize,
						status: [2]
					}
				if(this.areaId != 0){
					data.areaId = this.areaId
				}
				if(this.buildId != 0){
					data.buildId = this.buildId
				}
				let _this = this
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE}/policy/list`,
					header: {
						'Authorization': this.token,
					},
					method:'GET',
					data:data,
					success: function (res) {
						if(res.data.code == 200){
							console.log("政策list",res)
							for (var i = 0; i < res.data.data.policyList.length; i++) {
								_this.listPush(res.data.data.policyList[i])
							}
							if(res.data.data.policyList.length <= 0){
								_this.isLoadMore = false
							}else{
								_this.isLoadMore = false
								_this.loadStatus = 'nomore'
							}
						}
					},
				})
			},
			getCompanyList(){
				this.isLoadMore = false
				let data = {
						pageNo:this.pageNo,
						pageSize:this.pageSize,
						status: [4]
					}
				if(this.areaId != 0){
					data.areaId = this.areaId
				}
				if(this.industryId != 0){
					data.industryId = this.industryId
				}
				let _this = this
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE}/company-certification/collected-list`,
					header: {
						'Authorization': this.token,
					},
					method:'GET',
					data:data,
					success: function (res) {
						if(res.data.code == 200){
							console.log("企业list",res)
							for (var i = 0; i < res.data.data.customCollectedList.length; i++) {
								_this.listPush(res.data.data.customCollectedList[i])
							}
							if(res.data.data.customCollectedList.length <= 0){
								_this.isLoadMore = false
							}else{
								_this.isLoadMore = false
								_this.loadStatus = 'nomore'
							}
						}
						if(res.data.code == 1000){
							this.isLoadMore = false
							uni.navigateTo({
								url: '/pages/login/login'
							});
						}
					},
				})
			},
			getRuleFilter(){
				this.areaId = 0
				this.buildId = 0
				this.filterData = [
					{
						"name":'全部分类',
						"type": 'hierarchy-column',
						"submenu": [{
								"name": '全部城市',
								"value": 0,
								"submenu": [{
												"name": "全部楼盘",
												"value": 0
											}]
								},
							]
					},
				]
				let _this = this
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE}/qzw-building/all-city-build`,
					method:'GET',
					success: function (res) {
						console.log("楼盘信息", res)
						if(res.data.code == 200){
							let temp = res.data.data
							temp.forEach((item,index) => {
								let flag = true
								for (var i = 0; i < _this.filterData[0].submenu.length; i++) {
									if(item.buildCityAreaId == _this.filterData[0].submenu[i].value){  //
										let buildTemp = {}
										buildTemp.name = item.buildName
										buildTemp.value = item.buildId
										_this.filterData[0].submenu[i].submenu.push(buildTemp)
										flag = false
										break
									}
								}
								if(flag){
									let cityTemp = {
										"name": item.buildCity,
										"value": item.buildCityAreaId,
										"submenu": [{
												"name": "全部楼盘",
												"value": 0
											},
											{
												"name": item.buildName,
												"value": item.buildId,
											}
										]
									}
									_this.filterData[0].submenu.push(cityTemp)
								}
								let buildTemp = {}
								buildTemp.name = item.buildName
								buildTemp.value = item.buildId
								_this.filterData[0].submenu[0].submenu.push(buildTemp)
							})
							console.log('filter',_this.filterData)
							_this.getRuleList()
							try{

							}catch(e){
								//TODO handle the exception
							}
						}
					}
				})
			},
			getCompanyFilter(){
				this.areaId = 0
				this.industryId = 0
				let submenu = [{
												"name": "全部地域",
												"value": 0
											},
											{
												"name": "上海市",
												"value": 310100
											},
											{
												"name": "深圳市",
												"value": 440300
											},
											{
												"name": "成都市",
												"value": 510100
											}
								]
				this.filterData = [
					{
						"name":'全部分类',
						"type": 'hierarchy-column',
						"submenu": [{
								"name": '全部行业',
								"value": 0,
								"submenu": submenu
								},
							]
					},
				]
				let _this = this
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE}/industry/list`,
					method:'GET',
					header: {
						'Authorization': this.token,
					},
					data: {
						pageNo:0,//操作信息
						pageSize:100,
					},
					success: function (res) {
						console.log("楼盘信息", res)
						if(res.data.code == 200){
							let temp = res.data.data.industryList
							temp.forEach((item,index) => {
								let flag = true
								if(flag){
									let cityTemp = {
										"name": item.industryName,
										"value": item.id,
										"submenu": submenu
									}
									_this.filterData[0].submenu.push(cityTemp)
								}
							})
							console.log('filter',_this.filterData)
							_this.getCompanyList()
							try{

							}catch(e){
								//TODO handle the exception
							}
						}
					}
				})
			},
		},
		onShow() {
			this.token = uni.getStorageSync('token')
			this.pageNo = 1
			this.pageSize = 10
			this.recordList=[]
			if(this.activeIndex == 0){
				this.getCompanyFilter()
			}else{
				this.getRuleFilter()
			}

		},
		// onReady() {
		// 	const query = uni.createSelectorQuery().in(this);
		// 	query.select("#navbar").boundingClientRect(data => {
		// 	  console.log("得到布局位置信息" + JSON.stringify(data));
		// 	  console.log("节点离页面顶部的距离为" + data.top);
		// 	  this.HMfilterDropdownTop = data.height
		// 	}).exec();
		// }
	}
</script>

<style scoped lang="scss">
	/* 底部内边距为150rpx跟底部离一小段距离UI效果更好 */
	.container {
		padding-bottom: 710rpx;
		background-color: #FFFFFF;
	}
	.slot-wrap {
		display: flex;
		align-items: center;
		padding-left: 40rpx;
		font-size: 35rpx;
		font-weight: 700;
	}
	.slot-right{
		display: flex;
		align-items: flex-end;
		padding-left: 540rpx;
		font-size: 30rpx;
		color: #0000FF;
	}
	.tip-imgbo {
		flex-direction:flex;
		height: 45rpx;
		width: 45rpx;
		padding-left: 580rpx;
		margin-top: 15rpx;
		font-size: 35rpx;
	}
	.block-green {
		box-shadow:inset 0rpx 1rpx 0rpx 0rpx #a4e271;
		background:linear-gradient(to bottom, #5ddc54 5%, #0ba800 100%);
		background-color:#89c403;
		border-radius:10rpx;
		border:1rpx solid #74b807;
		display:inline-block;
		color:#ffffff;
		font-family:Arial;
		font-size:15rpx;
		font-weight:bold;
		height: 250rpx;
		width: 190rpx;
		text-decoration:none;
		text-shadow:0rpx 1rpx 0rpx #528009;
		margin: 100rpx 40rpx 25rpx 30rpx;
	}
	.block-blue {
		box-shadow:inset 0rpx 1rpx 0rpx 0rpx #00a6ff;
		background:linear-gradient(to bottom, #667aff 5%, #0600be 100%);
		background-color:#0099ff;
		border-radius:10rpx;
		border:1rpx solid #004fc5;
		display:inline-block;
		color:#ffffff;
		font-family:Arial;
		font-size:15rpx;
		font-weight:bold;
		height: 250rpx;
		width: 190rpx;
		text-decoration:none;
		text-shadow:0rpx 1rpx 0rpx #000086;
		margin: 20rpx 40rpx 30rpx 15rpx;
	}
	.block-purple {
		box-shadow:inset 0rpx 1rpx 0rpx 0rpx #aa55ff;
		background:linear-gradient(to bottom, #b5a2ff 5%, #aa55ff 100%);
		background-color:#aa55ff;
		border-radius:10rpx;
		border:1rpx solid #7339ac;
		display:inline-block;
		color:#ffffff;
		font-family:Arial;
		font-size:15rpx;
		font-weight:bold;
		height: 250rpx;
		width: 190rpx;
		text-decoration:none;
		text-shadow:0rpx 1rpx 0rpx #48246d;
		margin: 20rpx 15rpx 30rpx 15rpx;
	}
	.block-orange {
		box-shadow:inset 0rpx 1rpx 0rpx 0rpx #ffffff;
		background:linear-gradient(to bottom, #ff9e65 5%, #ff8800 100%);
		background-color:#c28100;
		border-radius:10rpx;
		border:1rpx solid #996600;
		display:inline-block;
		color:#ffffff;
		font-family:Arial;
		font-size:15rpx;
		font-weight:bold;
		height: 250rpx;
		width: 190rpx;
		text-decoration:none;
		text-shadow:0rpx 1rpx 0rpx #ce5d00;
		margin: 20rpx 15rpx 30rpx 15rpx;
	}
	.nav-choice-contract{
		height: 100rpx;
		width: 387rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		border-bottom: solid 5rpx #F1F1F1;
	}
	.choice-bar{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content:center;
		width: 750rpx;
		color: #808080;
	}
	.active-choice-contract{
		height: 100rpx;
		width: 387rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		font-weight:600;
		color: #DD524D;
		border-bottom: solid 5rpx #DD524D;
	}
</style>